﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Runtime.InteropServices;
using System.ComponentModel;

namespace Gmantis.Controls
{
    [StructLayout(LayoutKind.Sequential), TypeConverter(typeof(ZoomUnitTypeConverter))]
    public class ZoomUnit
    {
        private double _value;
        private ZoomUnitType _type;

        public ZoomUnit(double zoom)
        {
            this._type = ZoomUnitType.Fixed;
            this._value = zoom;
        }

        public ZoomUnit(double value, ZoomUnitType type)
        {
            this._type = type;
            this._value = value;
        }

        public ZoomUnitType Type
        {
            get { return this._type; }
        }

        public double Value
        {
            get { return this._value; }
        }

        public bool IsFixed
        {
            get { return (this._type == ZoomUnitType.Fixed); }
        }

        public bool IsFill
        {
            get { return (this._type == ZoomUnitType.Fill); }
        }

        public bool IsOneItem
        {
            get { return (this._type == ZoomUnitType.OneItem); }
        }

        public static ZoomUnit Fill
        {
            get { return new ZoomUnit(1.0, ZoomUnitType.Fill); }
        }

        public static ZoomUnit OneItem
        {
            get { return new ZoomUnit(1.0, ZoomUnitType.OneItem); }
        }

        public static bool operator ==(ZoomUnit gl1, ZoomUnit gl2)
        {
            return (gl1._type == gl2._type) && (gl1._value == gl2._value); 
        }

        public static bool operator !=(ZoomUnit gl1, ZoomUnit gl2)
        {
            return !(gl1 == gl2);
        }

        public override bool Equals(object obj)
        {
            return ((obj is ZoomUnit) && (this == (ZoomUnit)obj));
        }

        public override int GetHashCode()
        {
            return (this._type.GetHashCode() ^ this._value.GetHashCode());
        }

        public override string ToString()
        {
            switch (this._type)
            {
                case ZoomUnitType.Fixed:
                    return string.Format("{0}", this._value);
                case ZoomUnitType.OneItem:
                    return "OneItem";
            }
            return "Fill";
        }
    }

    public enum ZoomUnitType
    {
        Fixed,
        Fill,
        OneItem
    }
}
